/**
 * Created by novem on 15/9/25.
 */

    function pi(){
        return  3.1415926535898;
    }
    pow=Math.pow;
    sin=Math.sin;
    cos=Math.cos;
    asin=Math.asin;
    min=Math.min;
    sqrt=Math.sqrt;

window.onload=function(){
//    var geolocation = new BMap.Geolocation();
//    geolocation.getCurrentPosition(function(r) {
//        var storage = window.localStorage;
//        storage.setItem("lng", r.point.lng);
//        storage.setItem("lat", r.point.lat);
//    });
    var url = getUrl();
    var loc = getLoc();
    $.jsonp({
        url: 'http://'+url+'/api/spotsphoto/spots_photo_list',
        data: {},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {
            $.each(data.arrays,function(index,item) {
                earthRadius = 6371;
                var lat0 = (loc.lat * pi()) / 180;
                var lng0 = (loc.lng * pi()) / 180;
                var lat1 = (item.spots.spotsDimensions * pi()) / 180;
                var lng1 = (item.spots.spotsLongitude * pi()) / 180;
                calcLongitude = lng1 - lng0;
                calcLatitude = lat1 - lat0;
                stepOne = pow(sin(calcLatitude / 2), 2) + cos(lat0) * cos(lat1) * pow(sin(calcLongitude / 2), 2);
                stepTwo = 2 * asin(min(1, sqrt(stepOne)));
                calculatedDistance = earthRadius * stepTwo;
                item.distance=calculatedDistance.toFixed(1);
            });
            var complied_tpl = juicer($("#huace_tpl").text());
            var html = complied_tpl.render(data);
            //var jumpurl = "jumptoLogin(" + "'huace_jingdianhuace.html?spotsId=${item.spots.id}')";
            //html +='<div onclick="' + jumpurl + '">'
            $("#huace-list").append(html);
        },
        error: function (xOptions, textStatus) {
        }
    });
    //下拉
    $("#m_add").click(function(){
        $(".w_cebiaoti").slideToggle();
    });
}
function onBackKeyDown() {
    jumpbyback(0,"");
}